package com.xingchen.springboot3.validation;

import com.xingchen.springboot3.anno.State;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

/**
 *  校验规则 state 的实现类
 * @author weijingchen
 * @DateTime 2025-09-26
 */
public class StateValidation implements ConstraintValidator<State, String> {

    /**
     * 校验逻辑
     * @param value 将来要校验的数据
     * @param constraintValidatorContext
     * @return 如果返回false,则校验失败 否则校验成功
     */
    @Override
    public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
        // 提供校验规则
        if(value == null){
            return false;
        }
        if(value.equals("已发布") || value.equals("草稿")){
            return true;
        }
        return false;
    }
}
